//
//  WebSearchCell.swift
//  XingCeHelper
//
//  Created by 申铭 on 2022/10/21.
//

import UIKit

class WebSearchCell: BaseTableViewCell {

    var model: WebSearchCellModel?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        selectionStyle = .none
        separatorInset = UIEdgeInsets(top: 0, left: 999, bottom: 0, right: 0)
    }
    
    @IBAction func baidu(_ sender: Any) {
        guard var title = model?.title else { return }
        title = title.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
        let urlStr = "https://www.baidu.com/s?wd=\(title)"
        
        guard let url = URL(string: urlStr) else { return }
        let wk = WKWebViewController()
        wk.urlRequest = URLRequest(url: url)
        UIViewController.currentNavController()?.pushViewController(wk, animated: true)
    }
    
    @IBAction func renminwang(_ sender: Any) {
        guard var title = model?.title else { return }
        title = title.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
        let urlStr = "http://search.people.cn/s?keyword=\(title)"
        
        guard let url = URL(string: urlStr) else { return }
        let wk = WKWebViewController()
        wk.urlRequest = URLRequest(url: url)
        UIViewController.currentNavController()?.pushViewController(wk, animated: true)
    }
}
